<template>
<view>
	<view class="header">项目管理</view>
	<view class="table">
		<table border="0" width="95%" cellspacing="0" cellpadding="0" 
		v-for="(item,index) in list" :key="index">
			<tr>
				<td>{{item.name}}</td>
				<td>
					<image @click="del(item.id)" v-if="oaRole == 1 || oaRole == 3"
					src="/static/img/none_delete.png" alt=""></image>
				</td>
			</tr>
			<tr>
				<td>手工费</td>
				<td>{{item.fee}}</td>
			</tr>
			<tr>
				<td>使用物品</td>
				<td>使用数量</td>
			</tr>
			<tr v-for="(iitem,iindex) in item.goods" :key="iindex">
				<td>{{iitem.name}}</td>
				<td>{{iitem.use_num}}</td>
			</tr>
		</table>
	</view>
	<button class="buttonClass" @click="show" v-if="oaRole == 1 || oaRole == 3">添加项目</button>
	
	
	<projectAdd v-if="projectAddShow" @func="close"></projectAdd>
</view>
</template>
<script>
import request from '@/util/request.js'
import projectAdd from "@/components/manage/projectAdd.vue"//充值
export default {
	data() {
		return {
			//oaRole 1:店长2:员工3:商户
			oaRole:0,
			list:[],
			page:1,
			pageShow:true,
			projectAddShow:false
		}
	},
	components:{projectAdd},
	onLoad:function(e){
		uni.showLoading({
		    title: '加载中'  
		});
		this.getList();
		this.oaRole = uni.getStorageSync('oaRole')
		//this.oaRole = 2
	},
	methods: {
		getList:function(){
			var data = {
				oa_id:uni.getStorageSync('oa_id'),
				page:this.page,
			}
			var that = this
			request({
				url: 'manage/card/cardList',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.data.last_page <= that.page){
						that.pageShow = false
					}
					if(that.page == 1){
						that.list = res.data.data.data
					}else{
						var list = that.list
						that.list = list.concat(res.data.data.data)
					}
				},
			})
		},
		onReachBottom: function(){
			if(this.pageShow){
				 //当前不是最后一页可加载
				 this.page = this.page + 1
				 uni.showLoading()
				 this.getList();
			}
		},
		show:function(){
			this.projectAddShow = true
		},
		del:function(id){
			uni.showModal({
				title: '提示',
				content: '是否要删除吗?',
				success: function (res) {
					if (res.confirm) {
						that.putProject(id)
					}else if (res.cancel) {
						//console.log('用户点击取消');
					}
				}
			});
		},
		putProject:function(id){
			var data = {id:id}
			var that = this
			request({
				url: 'manage/card/del',
				method: 'delete',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.showToast({
							title: '删除成功!!',
							icon: "success", 
							position:'bottom',
						});
						uni.showLoading()
						that.getList();
					}else{
						uni.showToast({
							title: '删除失败!!',
							icon: "none", 
							position:'bottom',
						});
					}
				},
			})
		},
		close:function(data){
			this[data.model] = false
			if(data.type == 1){
				this.getList()
			}
		}
	},
}
</script>
<style>
.header{
    width:100%;
    height:80rpx;
    line-height: 80rpx;
    text-align: center;
    background:#00b300;
    color:#fff;
}
.table{
	width:100%;
	padding:10rpx 20rpx 120rpx 20rpx;
}
table{
	margin-top:30rpx;
}
td{
	border:1rpx solid #C8C7CC;
	text-align: center;
	height:70rpx;
	line-height:70rpx;
}
td image{
	width:30rpx;
	height:30rpx;
}
</style>